package org.scala.javafx.apps

import javafx.stage.Stage
import javafx.scene.Group
import javafx.scene.control.Button
import javafx.event.EventHandler
import javafx.scene.input.MouseEvent
import javafx.scene.Node
import javafx.scene.control.Label
import javafx.application.Application
import javafx.scene.Scene
import org.scala.javafx.control.ArrowButton
import org.scala.javafx.control.ArrowButtonSkin

class ArrowButtonTest extends Application {
  override def start(stage: Stage): Unit = {
    stage.setTitle("The JavaFX Bank")
    // Create the node structure for display
    val rootNode = new Group()
    val normalBtn = new Button("Close")
    normalBtn.setTranslateX(140)
    normalBtn.setTranslateY(170)
    val s = stage
    normalBtn.setOnMouseClicked(new EventHandler[MouseEvent]() {
      override def handle(event: MouseEvent): Unit = {
        // Close the stage (accessible through the scene graph)
        val node = event.getSource().asInstanceOf[Node]
        node.getScene().getWindow().hide()
      }
    })
     
    // Create a directional arrow button to display account information
    val accountBtn = new ArrowButton("Accounts")
    accountBtn.setDirection(ArrowButtonSkin.RIGHT)
    accountBtn.setTranslateX(125)
    accountBtn.setTranslateY(10)
    accountBtn.setOnMouseClicked(new EventHandler[MouseEvent]() {
      override def handle(event: MouseEvent): Unit = {
      }
    })
     
    // Handle arrow button press
    accountBtn.setOnMouseClicked(new EventHandler[MouseEvent]() {
      override def handle(event: MouseEvent): Unit = {
        System.out.println("Arrow button pressed")
        accountBtn.setText("MOO")
      }
    })
     
    // Some description text
    val description = new Label(
            "Thanks for logging into the\n"
            + "JavaFX Bank. Click the button\n"
            + "above to move to the next \n"
            + "screen, and view your active \n"
            + "bank accounts.")
    description.setTranslateX(10)
    description.setTranslateY(50)
    
    rootNode.getChildren().add(accountBtn)
    rootNode.getChildren().add(description)
    rootNode.getChildren().add(normalBtn)
    
    val scene = new Scene(rootNode, 200, 200)
    stage.setScene(scene)
    stage.show
  }
}

object ArrowButtonTest {
  def main(args: Array[String]): Unit = {
    Application.launch(classOf[ArrowButtonTest], args)
  }
}
